﻿@using CuongHanh
@using CuongHanh.Context
@using CuongHanh.Models
@using Ext.Net.Utilities
@model CuongHanh.Models.OrderForGem
@{
    Layout = "../Shared/_GemLayout.cshtml";
    ViewBag.Title = "Thanh Toan";

}
<script type="text/javascript">
    var datas = {};
    $(document).ready(function () {
        datas.SubTotal = parseInt($('#sub-total-price').val());
        datas.ShippingCost = 0;
        datas.UtilityFee = 0;
        $('#InVietNam-true').attr('checked', 'checked');
        GetShippingAddress('True');
        $('.shipping-address').click(function() {
            var value = $(this).val();
            if (value) {
                GetShippingAddress(value);
            }
        });

        $('#shippingAddress').change(function() {
            if ($(this).val()) {
                var fees = $(this).val().split(',');
                if (fees.length == 3) {
                    $('#ServiceFeeId').val(fees[0]);
                    datas.ShippingCost = parseInt(fees[1]);
                    datas.UtilityFee = parseInt(fees[2]);
                    $('#shipping-cost').html(formatNumber(datas.ShippingCost, true));
                    $('#utility-fee').html(formatNumber(datas.UtilityFee, true));
                    $('#total-price').html(formatNumber(getTotalPrice(), false));
                }
            }
        });
    });

    function getTotalPrice() {
        return datas.SubTotal + datas.ShippingCost + datas.UtilityFee;
    }

    function GetShippingAddress(isDomestic) {
        $.post('@Url.Action("ServiceFees")', { isDomestic: isDomestic }, function (result) {
            var shippingAddresses = '';
            for (var i = 0; i < result.length; i++) {
                shippingAddresses += '<option value="' + result[i].Value + '">' + result[i].Text + '</option>';
            }
            $('#shippingAddress').html(shippingAddresses);
        });
    }
</script>


<div class="block account">
    <p class="title">@Html.GetResource("cartinfomation")</p>
    @Html.Partial("Partial/_CartInfoOfGemForPayment")
</div>


<div class="block account">
    <p class="title">@Html.GetResource("deliveryaddress")</p>
    @using (Html.BeginForm("CreateOrderForGem",
            "Order",
            FormMethod.Post))
    {
        @Html.AntiForgeryToken()
        @Html.HiddenFor(c=>c.ServiceFeeId)
        <div class="form login">
            <div class="field" style="padding: 0;">
                @Html.LabelFor(c => c.Name,
                        Html.GetResource("fullname"),
                        new
                        {
                                @class = "field_L"
                        })
                @Html.TextBoxFor(c => c.Name,
                        new
                        {
                                style = "width:330px;"
                        })
            </div>
            <div class="field" style="padding: 0;">
                @Html.LabelFor(c => c.Phone,
                        Html.GetResource("phone"),
                        new
                        {
                                @class = "field_L"
                        })
                @Html.TextBoxFor(c => c.Phone,
                        new
                        {
                                style = "width:330px;"
                        })
            </div>
             <div class="field" style="padding: 0;">
                @Html.LabelFor(c => c.Phone,
                        Html.GetResource("email"),
                        new
                        {
                                @class = "field_L"
                        })
                @Html.TextBoxFor(c => c.Email,
                        new
                        {
                                style = "width:330px;"
                        })
            </div>
            <div class="field" style="padding: 0;">
                @Html.LabelFor(c => c.Address,
                        Html.GetResource("address"),
                        new
                        {
                                @class = "field_L"
                        })
                @Html.TextBoxFor(c => c.Address,
                        new
                        {
                                style = "width:330px;"
                        })
            </div>
            <div class="field" style="padding: 0; padding-bottom: 3px;">
               <label class="field_L" style="width: 130px;">@Html.GetResource("deliveryaddress"):</label>
                @Html.RadioButtonFor(c=>c.InVietNam,true,new
                                                         {
                                                                 id="InVietNam-true",
                                                                 style="margin-top: 14px;",
                                                                 @class="shipping-address"
                                                         })
                     <span style="margin-top: 2px;">@Html.GetResource("vietnam")</span>
                     @Html.RadioButtonFor(c=>c.InVietNam,false,new
                                                         {
                                                                 id="InVietNam-false",
                                                                 style="margin: 16px 0 0 20px;",
                                                                 @class="shipping-address"
                                                                 
                                                         })
                
                     <span style="margin-top: 2px;">@Html.GetResource("orther")</span>
               
               
            </div>
            <div class="field" style="padding: 0px;">
               
                @Html.DropDownListFor(c=>c.ShippingAddress,new List<SelectListItem>(),
                        new
                        {
                            Id="shippingAddress",    
                            style = "width:350px;",@class="combobox-inner"
                                
                        })

            </div>
            <div class="field" style="padding: 0;">
                @Html.LabelFor(c => c.Remark,
                        Html.GetResource("remark"),
                        new
                        {
                                @class = "field_L"
                        })
                @Html.TextAreaFor(c => c.Remark,
                        new
                        {
                                style = "height:50px;width:335px;"
                        })
            </div>
            
            <div class="field" style="padding: 0;">
                <label class="field_L"></label><input class="btn_blue" type="submit" onclick="" value="@Html.GetResource("saveandpayment")" />
            </div>
        </div>
    }
    <div class="clear"></div>
    @if(Html.GetLanguageName() == AppUtil.LANGUAGE_EN)
    {
        @Html.Partial("Partial/_TiGia")
    }
</div>